package com.rigsofrods.truckeditor.gui.editor;

import java.util.Map;

import javax.swing.JComponent;
import javax.swing.tree.TreePath;

public class SectionEditorFactory {

	private static Map<String, JComponent> editors;
	
	public static JComponent getEditor(TreePath[] paths){
		System.out.print("gui.editor.SectionEditorFactory.getEditor()\n");
		if(paths.length == 0) return null;
		boolean same = haveSameParent(paths);
		if(!same || paths[0].getPathCount() <= 2) return null;	//is section name?
		Object section = paths[0].getParentPath().getLastPathComponent();
		
		return new SectionStringEditor();
	}
	
	private static boolean haveSameParent(TreePath[] paths) {
		if(paths.length == 0) return true;
		TreePath parent = paths[0].getParentPath();
		int i = 1;
		boolean same = true;
		while(same && i < paths.length){
			if(paths[i].getParentPath() != parent)
				same = false;
			i++;
		}
		return same;
	}
}
